#ifndef CHOOSEFRIENDDIALOG_H
#define CHOOSEFRIENDDIALOG_H

#include <QDialog>
#include <QWidget>
#include <QLayout>
#include <QScrollArea>
#include <QCheckBox>
#include <QPushButton>
#include <QLabel>
#include <QPainter>
#include <QStyle>
#include <QScrollBar>
#include <QScrollArea>
#include "model/data.h"
#include "model/debug.h"

class ChooseFriendDialog;

class ChooseFriendItem : public QWidget
{
    Q_OBJECT
public:
    QCheckBox* checkBox;
    // 该对象的持有者
    ChooseFriendDialog* owner;
    QString userId;
    QIcon avatar;
    QString name;
    bool isHover;
    ChooseFriendItem(ChooseFriendDialog* owner, const QString& userId, const
                     QIcon& avatar, const QString& name, bool checked = false);
    // 此处为了设置背景⾊, 采取⼿绘的⽅式.
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
private:
    void toggleCheckBox(bool checked);
};


class ChooseFriendDialog : public QDialog
{
    Q_OBJECT
public:
    ChooseFriendDialog(const QString& userId, QWidget* parent = nullptr);
    void addFriend(const QString& userId, const QIcon avatar, const QString&
                   name, bool checked);
    void addSelectedFriend(const QString& userId, const QIcon avatar, const
                           QString& name);
    void deleteSelectedFriend(const QString& userId);
private:
    // 保存左侧待选中好友列表的 container
    QWidget* totalContainer;
    // 保存右侧已选中好友列表的 container
    QWidget* selectedContainer;
    // 保存弹出当前窗⼝的好友是哪个
    QString userId;
    void initLeft(QHBoxLayout* layout);
    void initRight(QHBoxLayout* layout);
};

#endif
